package moltencore.network.protocol;

import spark.network.protocol.Base;
import spark.network.Util;
import spark.math.Vector2;

public class CannonNewTargetDirection extends Base {
	public static final short TYPE = 0x50;
	private static final byte[] TYPE_BYTES = Util.makeBytes(TYPE);

	private long clientId;
	private static final int CLIENT_ID_OFFSET = Base.SIZE;
	private static final int CLIENT_ID_LENGTH = Long.SIZE / 8;

	private Vector2 aimVector;
	private static final int AIM_VECTOR_OFFSET = CLIENT_ID_OFFSET + CLIENT_ID_LENGTH;
	private static final int AIM_VECTOR_LENGTH = Vector2.SIZE / 8;

	protected static final int SIZE =
			Base.SIZE +
			CLIENT_ID_LENGTH +
	        AIM_VECTOR_LENGTH;

	public CannonNewTargetDirection() {
		super(false, TYPE_BYTES);
	}

	public long getClientId() {
		return clientId;
	}

	public void setClientId(long clientId) {
		this.clientId = clientId;
	}

	public Vector2 getAimVector() {
		return aimVector;
	}

	public void setAimVector(Vector2 aimVector) {
		this.aimVector = aimVector;
	}

	@Override
	public void getBytes(byte[] buffer) {
		super.getBytes(buffer);
		Util.arraycopy(Util.makeBytes(clientId), 0, buffer, CLIENT_ID_OFFSET);
		Util.arraycopy(Util.makeBytes(aimVector), 0, buffer, AIM_VECTOR_OFFSET);
	}

	@Override
	public void fill(byte[] buffer) {
		super.fill(buffer);
		clientId = Util.makeLong(buffer, CLIENT_ID_OFFSET);
		aimVector = Util.makeVector2(buffer, AIM_VECTOR_OFFSET);
	}

	@Override
	public int getSize() {
		return SIZE;
	}

	public static CannonNewTargetDirection create(byte[] buffer, long receiveTime) {
		CannonNewTargetDirection packet = new CannonNewTargetDirection();
		packet.fill(buffer);
		return packet;
	}
}
